package org.wk.core.db.dao;

import java.io.Serializable;

import javax.persistence.EntityManager;

import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
import org.springframework.data.repository.core.RepositoryInformation;
import org.springframework.data.repository.core.RepositoryMetadata;

/**
 * 
 * @ClassName	: GenericRepositoryFactory
 * @Package		：org.wk.core.db.dao
 * @Author df.w 
 * @Create Time	：2018年5月2日 上午9:59:05
 * @Description	: 
 * @param <T>
 * @param <S>
 */
public class GenericRepositoryFactory<T, S extends Serializable> extends JpaRepositoryFactory {
	private EntityManager entityManager;

    public GenericRepositoryFactory(EntityManager entityManager) {
        super(entityManager);
        this.entityManager = entityManager;
    }

	@SuppressWarnings("unchecked")
	@Override
    protected Object getTargetRepository(RepositoryInformation information) {
        return new SimpleGenericJpaRepository<T, S>((Class<T>) information.getDomainType(), entityManager);
    }

    @Override
    protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
        return SimpleGenericJpaRepository.class;
    }
 
}
